package com.wecommodule.bpm.ext.framework.config;

import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.Collections;

/**
 * 接口文档 配置类
 *
 */
@EnableSwagger2WebMvc
@Configuration
public class SwaggerConfig {
    @Bean
    @Profile("prod")
    public Docket prodDocket() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket.enable(false);
        return docket;
    }

    @Bean
    @Profile("!prod")
    @NotNull
    public Docket apiV3Docket() {
        //指定使用Swagger2规范
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        //描述字段支持Markdown语法
                        .description("# 统一流程平台外部扩展服务 RESTful APIs")
                        .termsOfServiceUrl("https://cndrealty.com/")
                        .contact(new Contact("YeZhenXin","https://cndrealty.com/","6032508@qq.com"))
                        .version("1.0")
                        .build())
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.wecommodule.bpm.ext.biz"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    @Bean
    public ApiInfo buildAPIInfo() {
        Contact contact = new Contact("统一流程外部扩展项目开发团队", "", "bpm@cndrealty.com");
        return new ApiInfo( "统一流程平台外部扩展服务 APIs", "RESTFul APIs of 统一流程平台外部扩展服务" ,
                "current", "", contact, "", "", Collections.emptyList());
    }
}
